package ge.tsu.java.project.server;

import ge.tsu.java.project.commons.Contact;
import ge.tsu.java.project.commons.Contact.Status;
import ge.tsu.java.project.commons.Protocol;

/** This is how server sees user **/
public class Client {

	private String id;
	private ClientProcessor processor;

	public Client(String id) {
		this.id = id;
	}

	public String getId() {
		return id;
	}

	public ClientProcessor getProcessor() {
		return processor;
	}

	public void setProcessor(ClientProcessor processor) {
		this.processor = processor;
	}

	public Protocol getProtocol() {
		if (processor == null) {
			return null;
		}
		return processor.getProtocol();
	}
	
	public Contact toContact(Status status) {
		Contact contact = new Contact();
		contact.setId(id);
		contact.setStatus(status);
		return contact;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof Client))
			return false;
		Client other = (Client) obj;
		return id != null ? id.equals(other.id) : false;
	}

}
